﻿<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<![endif]-->
<link href="../css/formcheck.css" rel="stylesheet" type="text/css" />
<link rel="import" href="../includes/baseInclude.html">
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>合同管理</title>
</head>
<body ng-app="sopApp" ng-controller="sopCtrl" style="margin-top:16px">
	<article class="page-container">
		<form method="post" name="someForm">
			<div class="panel-primary">
				<div class="panel-header text-c" id='title'>sop信息</div>
				<div class="panel-body">
					<table class="table table-border table-bg table-bordered table-layout:fixed;">
						<tbody class="text-c ">
							<tr>
								<th style="width:139px;"><span class='c-red'>*</span>sop名称</th>
								<td style="width:207px;">
									<div style="height: 27px;"
										 ng-init="nameVailData=
                                         [{cond:'someForm.name.$error.maxlength',msg:'至多20个字符'},
                                          {cond:'someForm.name.$error.required&&someForm.name.$dirty',msg:'sop名称不能为空'}]">
										<input  ng-model="sopName" type="text" class="input-text radius size-S" value="" placeholder="请输入sop名称,最多20字符"
												ng-class="{error:someForm.name.$error.maxlength||someForm.name.$error.required&&someForm.name.$dirty}"
												name="name" ng-maxlength="20" maxlength="21" required>
                                            <span ng-repeat="nameMessage in nameVailData">
                                            <span class="userErrorMessage " ng-show="{{nameMessage.cond}}" ng-bind="nameMessage.msg"></span>
                                            </span>
									</div>
								</td>
								<th style="width:174px;">所有者</th>
								<td style="width:207px;">
									<div style="height: 27px;"
										 ng-init="ownerVailData=
                                         [{cond:'someForm.owner.$error.maxlength',msg:'至多20个字符'},
                                          ]">
										<input  ng-model="owner" type="text" class="input-text radius size-S" value="" placeholder="请输入所有者"
												ng-class="{error:someForm.owner.$error.maxlength&&someForm.owner.$dirty}"
												name="owner" ng-maxlength="20" maxlength="21">
                                            <span ng-repeat="ownerMessage in ownerVailData">
                                            <span class="userErrorMessage " ng-show="{{ownerMessage.cond}}" ng-bind="ownerMessage.msg"></span>
                                            </span>
									</div>
								</td> 
							</tr>
							<tr>
								<th>开始时间</th>
								<td style="width:207px;">
									<input onclick="laydate()"  def-laydate type="text" id="startTime"  ng-model="startTime" class="laydate-icon radius input-text Wdate"/>
								</td>
								<th>状态</th>
								<td style="width: 225px;height: 27px;">
									<div style="height: 27px;"
										 ng-init="contractHaoVailData=
                                         [{cond:'someForm.contractHao.$error.maxlength',msg:'至多20个字符'},
                                          {cond:'someForm.contractHao.$error.pattern&&someForm.contractHao.$dirty',msg:'编号格式错误'}]">
										<input  ng-model="contract.contractNumber" type="text" class="input-text radius size-S" value="" placeholder="请选择状态"
												ng-class="{error:someForm.contractHao.$error.maxlength||someForm.contractHao.$error.pattern&&someForm.contractHao.$dirty}"
												name="contractHao" ng-maxlength="20" maxlength="21" ng-pattern="/^[A-Za-z0-9]+$/">
                                            <span ng-repeat="contractHaoMessage in contractHaoVailData">
                                            <span class="userErrorMessage " ng-show="{{contractHaoMessage.cond}}" ng-bind="contractHaoMessage.msg"></span>
                                            </span>
									</div>
								</td>
							</tr>
							<tr>
							<th>执行人</th>
							<td colspan=3>
							    <div style="height: 27px;" ng-init="executorVailData=
                                     [{cond:'someForm.executor.$error.maxlength',msg:'至多300个字符'}]">
										<input  ng-model="executor" type="text" class="input-text radius size-S" value="" placeholder="请输入执行人姓名"
												ng-class="{error:someForm.executor.$error.maxlength&&someForm.executor.$dirty}"
												name="executor" ng-maxlength="300" maxlength="301">
                                            <span ng-repeat="executorMessage in executorVailData">
                                            <span class="userErrorMessage " ng-show="{{executorMessage.cond}}" ng-bind="executorMessage.msg"></span>
                                            </span>
								</div>
							</td>
							</tr>
						</tbody>
					</table>
				</div>
			</div>
			<div class=" text-c" style="text-align: center;margin-bottom: 30px;">
				<input class="btn btn-primary radius" type="button" ng-disabled="someForm.$invalid"
					   ng-click="addContractSubmit()" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</form>
	</article>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
	<script type="text/javascript" src="../js/laydate/laydate.js"></script>
    <script type="text/javascript" src="../lib/jquery/jquery.params.js"></script>
    <script type="text/javascript" src="../js/instruct.js"></script>
<script>
	//angularJs post 提交时HTTP头设置
	var transform = function(data) {
		return $.param(data);
	}, postCfg = {
		headers : {
			'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
		},
		transformRequest : transform
	};
	var app = angular.module('sopApp', []);
	app.directive('onFinishRenderFilters', function($timeout) {
		return {
			restrict : 'A',
			link : function(scope, element, attr) {
				if (scope.$last === true) {
					$timeout(function() {
						scope.$emit('ngRepeatFinished');
					});
				}
			}
		};
	});
	app.controller('sopCtrl', function($scope, $http) {
		var contractId = $.query.get("editId");
		$scope.infoContractId = contractId;
		$scope.editId=contractId;
		/*添加，修改*/
		$scope.getTypeVlue = function(title,grup){
			$scope.contract.industry = grup;
		};
		if($scope.infoContractId == null || $scope.infoContractId ==""){

		}else{
			var data = {
				'id':$scope.infoContractId
			};

		}

		$scope.addContractSubmit = function(){
			var addData = {
				'name':$scope.contract.name,
				'number':$scope.contract.number,
			};
			if($scope.infoContractId == null || $scope.infoContractId ==""){
				$http.post('/salesBidding/addBidding',addData,postCfg)
						.success(function(resp){
							if(validateSuccessData(resp)){
								window.parent.layer.msg('添加成功',{icon:1,time:1000});
								window.parent.refresh();
								layer_close();
							}else{
								layer.msg(resp.errorMessage,{icon:2,time:1000});
							}
						});
			}else{
				$http.post('/salesBidding/updateBidding',addData,postCfg)
						.success(function(resp){
							if(validateSuccessData(resp)){
								window.parent.layer.msg('修改成功',{icon:1,time:1000});
								window.parent.refresh();
								layer_close();
							}else{
								layer.msg(resp.errorMessage,{icon:2,time:1000});
							}
						});
			}
		};

		/*错误信息提示*/
		function validateSuccessData(data){
			if((typeof(data) == 'string') && (data == 'true')){
				return true;
			}
			if((typeof(data) == 'boolean') && (data == true)){
				return true;
			}
			if(data.id){
				return true;
			}
			return false;
		}
	});

</script>
</body>
</html>